from unittest.case import TestCase
from nameMangler import SmalltalkNameMangler, PythonNameMangler

__author__ = 'romilly'

# TODO change Field to Attribute throughout

class TestSmalltalkNameMangler(TestCase):
    def setUp(self):
        self.mangler = SmalltalkNameMangler()

    def convertsClassNameToTableName(self):
        self.assertEquals(self.mangler.makeTableName('Foo'),'FOO')
        self.assertEquals(self.mangler.makeTableName('FooBar'),'FOO_BAR')

    def testConvertsFieldNameToColumnName(self):
        self.assertEquals(self.mangler.makeColumnName('foo'),'FOO')
        self.assertEquals(self.mangler.makeColumnName('foo'),'FOO')
        self.assertEquals(self.mangler.makeColumnName('foo2'),'FOO2')
        self.assertEquals(self.mangler.makeColumnName('fooBar'),'FOO_BAR')

    def testConvertsColumnNameToFieldName(self):
        self.assertEquals(self.mangler.makeFieldName('FOO'),'foo')
        self.assertEquals(self.mangler.makeFieldName('FOO2'),'foo2')
        self.assertEquals(self.mangler.makeFieldName('FOO_BAR'),'fooBar')
        self.assertEquals(self.mangler.makeFieldName('FOO_'),'foo')

class TestPythonNameMangler(TestCase):
    def setUp(self):
        self.mangler = PythonNameMangler()

    def convertsClassNameToTableName(self):
        self.assertEquals(self.mangler.makeTableName('Foo'),'FOO')
        self.assertEquals(self.mangler.makeTableName('FooBar'),'FOO_BAR')

    def testConvertsFieldNameToColumnName(self):
        self.assertEquals(self.mangler.makeColumnName('foo'),'FOO')
        self.assertEquals(self.mangler.makeFieldName('FOO_BAR'),'foo_bar')

    def testConvertsColumnNameToFieldName(self):
        self.assertEquals(self.mangler.makeFieldName('FOO'),'foo')
        self.assertEquals(self.mangler.makeFieldName('FOO2'),'foo2')
        self.assertEquals(self.mangler.makeFieldName('FOO_BAR'),'foo_bar')